﻿using PMS.XCMG.Entity;
using PMS.XCMG.IBusiness;
using PMS.XCMG.Models;
using PMS.XCMG.Util;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace PMS.XCMG.Api.Controllers
{
    /// <summary>
    /// Sys_UserRole
    /// </summary>
    public class Sys_UserRoleController : BaseController
    {
        public ISys_UserRoleBusiness Bus { get; set; }
        public Sys_UserRoleController(ISys_UserRoleBusiness bus)
        {
            this.Bus = bus;
        }

        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        [HttpPost]
        public Task<PageResult<Sys_UserRole>> GetPageAsync(PageInput<Sys_UserRoleQM> query)
        {
            return this.Bus.GetPageResultAsync(query);
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="roleIds">角色Ids</param>
        /// <returns></returns>
        [HttpPost]
        [Transaction]
        public Task<int> SaveAsync(string userId,List<string> roleIds)
        {
            return this.Bus.AddAsync(userId, roleIds);
        }

        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="roleIds"></param>
        /// <returns></returns>
        [HttpDelete]
        [Transaction]
        public Task<int> DeleteAsync(string userId, List<string> roleIds)
        {
            return this.Bus.DeleteAsync(userId, roleIds);
        }
    }
}
